package com.daxia.bumall.util;

import org.jsoup.Jsoup;

public class WxUtils {
    private static int get = 0;
    private static int post = 1;
    
    public static String get(String url) {
        return request(url, get);
    }
    
    public static String post(String url) {
        return request(url, post);
    }

    private static String request(String url, int method) {
        int failedTimes = 0;
        while (true) {
            try {
                if (method == get) {
                    return Jsoup.connect(url).ignoreContentType(true).get().text();
                } else {
                    return Jsoup.connect(url).ignoreContentType(true).post().text();
                }
            } catch (Exception e) {
                if (failedTimes ++ > 2) {
                    throw new RuntimeException(e.getMessage(), e);
                }
            }
        }
    }

}
